bitkeeper revision 1.1488 (428e0104FPjt2icUt6-UvaVbiv-4aQ)
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Fri, 20 May 2005 15:23:48 +0000 (15:23 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Fri, 20 May 2005 15:23:48 +0000 (15:23 +0000)
XendDomainInfo.py, xc.c, xc_linux_restore.c, xc_domain.c, xc.h:
  Split pincpu, setcpuweight, setmaxmem and memory increase reservation
  out of xc_domain_create.  Add glue to get the missing functions exposed
  to python and use.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
tools/libxc/xc.h
tools/libxc/xc_domain.c
tools/libxc/xc_linux_restore.c
tools/python/xen/lowlevel/xc/xc.c
tools/python/xen/xend/XendDomainInfo.py

index 3b464eb6838877903947009e1f4370f18b974717..591f9ae187e2950c49352e1870348f3364c5e588 100644 (file)
@@ -124,9 +124,6 @@ typedef struct {
 
 typedef dom0_getdomaininfo_t xc_domaininfo_t;
 int xc_domain_create(int xc_handle, 
-                     unsigned int mem_kb, 
-                     int cpu,
-                     float cpu_weight,
                      u32 *pdomid);
 
 
@@ -407,6 +404,10 @@ int xc_domain_setmaxmem(int xc_handle,
                         u32 domid, 
                         unsigned int max_memkb);
 
+int xc_domain_memory_increase_reservation(int xc_handle,
+                                          u32 domid, 
+                                          unsigned int mem_kb);
+
 typedef dom0_perfc_desc_t xc_perfc_desc_t;
 /* IMPORTANT: The caller is responsible for mlock()'ing the @desc array. */
 int xc_perfc_control(int xc_handle,
index 345af149f212e7470100e1c009c8eb67910a2693..b51c1c608894fba5b292ee3fe3087aad2ffb6d52 100644 (file)
@@ -9,15 +9,10 @@
 #include "xc_private.h"
 
 int xc_domain_create(int xc_handle,
-                     unsigned int mem_kb, 
-                     int cpu,
-                     float cpu_weight,
                      u32 *pdomid)
 {
-    int err, errno_saved;
+    int err;
     dom0_op_t op;
-    u32 vcpu = 0; /* FIXME, hard coded initial pin to vcpu 0 */
-    cpumap_t cpumap = 1 << cpu;
 
     op.cmd = DOM0_CREATEDOMAIN;
     op.u.createdomain.domain = (domid_t)*pdomid;
@@ -25,33 +20,7 @@ int xc_domain_create(int xc_handle,
         return err;
 
     *pdomid = (u16)op.u.createdomain.domain;
-
-    if ( (cpu != -1) &&
-         ((err = xc_domain_pincpu(xc_handle, *pdomid, vcpu, &cpumap)) != 0) )
-        goto fail;
-
-    if ( (err = xc_domain_setcpuweight(xc_handle, *pdomid, cpu_weight)) != 0 )
-        goto fail;
-
-    if ( (err = xc_domain_setmaxmem(xc_handle, *pdomid, mem_kb)) != 0 )
-        goto fail;
-
-    if ( (err = do_dom_mem_op(xc_handle, MEMOP_increase_reservation,
-                              NULL, mem_kb/4, 0, *pdomid)) != (mem_kb/4) )
-    {
-        if ( err > 0 )
-            errno = ENOMEM;
-        err = -1;
-        goto fail;
-    }
-
     return 0;
-
- fail:
-    errno_saved = errno;
-    (void)xc_domain_destroy(xc_handle, *pdomid);
-    errno = errno_saved;
-    return err;
 }    
 
 
@@ -256,3 +225,21 @@ int xc_domain_setmaxmem(int xc_handle,
     op.u.setdomainmaxmem.max_memkb = max_memkb;
     return do_dom0_op(xc_handle, &op);
 }
+
+int xc_domain_memory_increase_reservation(int xc_handle,
+                                          u32 domid, 
+                                          unsigned int mem_kb)
+{
+    int err;
+
+    err = do_dom_mem_op(xc_handle, MEMOP_increase_reservation, NULL,
+                        mem_kb / 4, 0, domid);
+    if (err == mem_kb / 4)
+        return 0;
+
+    if (err > 0) {
+        errno = ENOMEM;
+        err = -1;
+    }
+    return err;
+}
index e363f43012f3e1cff22ae6a2e1870f95e56e1004..afabadb17adaf109fa63633edfaf1b10437fa9bc 100644 (file)
@@ -167,14 +167,31 @@ int xc_linux_restore(int xc_handle, XcIOContext *ioctxt)
     }
 
     /* Create domain on CPU -1 so that it may auto load-balance in future. */
-    if ( xc_domain_create(xc_handle, nr_pfns * (PAGE_SIZE / 1024),
-                          -1, 1, &dom) )
+    if ( xc_domain_create(xc_handle, &dom) )
     {
-       xcio_error(ioctxt, "Could not create domain. pfns=%ld, %ldKB",
-                  nr_pfns, nr_pfns * (PAGE_SIZE / 1024));
+        xcio_error(ioctxt, "Could not create domain.");
         goto out;
     }
-    
+    if ( xc_domain_setcpuweight(xc_handle, dom, 1) )
+    {
+        xcio_error(ioctxt, "Could not set domain cpuweight.");
+        goto out;
+    }
+    if ( xc_domain_setmaxmem(xc_handle, dom, nr_pfns * (PAGE_SIZE / 1024)) )
+    {
+        xcio_error(ioctxt, "Could not set domain maxmem. pfns=%ld, %ldKB",
+                   nr_pfns, nr_pfns * (PAGE_SIZE / 1024));
+        goto out;
+    }
+    if ( xc_domain_memory_increase_reservation(xc_handle, dom,
+                                               nr_pfns * (PAGE_SIZE / 1024)) )
+    {
+        xcio_error(ioctxt,
+                   "Could not increase domain memory reservation. pfns=%ld",
+                   nr_pfns);
+        goto out;
+    }
+
     ioctxt->domain = dom;
     xcio_info(ioctxt, "Created domain %u\n", dom);
 
index d77540803a12431d2b8c54928430e7494075a160..39045370c7303bbe38c32c605d75be33b9a9d196 100644 (file)
@@ -69,20 +69,15 @@ static PyObject *pyxc_domain_create(PyObject *self,
 {
     XcObject *xc = (XcObject *)self;
 
-    unsigned int mem_kb = 0;
-    int          cpu = -1;
-    float        cpu_weight = 1;
     u32          dom = 0;
     int          ret;
 
-    static char *kwd_list[] = { "dom", "mem_kb", "cpu", "cpu_weight", NULL };
+    static char *kwd_list[] = { "dom", NULL };
 
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiif", kwd_list, 
-                                      &dom, &mem_kb, &cpu, &cpu_weight))
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwd_list, &dom))
         return NULL;
 
-    if ( (ret = xc_domain_create(
-                    xc->xc_handle, mem_kb, cpu, cpu_weight, &dom)) < 0 )
+    if ( (ret = xc_domain_create(xc->xc_handle, &dom)) < 0 )
         return PyErr_SetFromErrno(xc_error);
 
     return PyInt_FromLong(dom);
@@ -171,6 +166,28 @@ static PyObject *pyxc_domain_pincpu(PyObject *self,
     return zero;
 }
 
+static PyObject *pyxc_domain_setcpuweight(PyObject *self,
+                                         PyObject *args,
+                                         PyObject *kwds)
+{
+    XcObject *xc = (XcObject *)self;
+
+    u32 dom;
+    float cpuweight = 1;
+
+    static char *kwd_list[] = { "dom", "cpuweight", NULL };
+
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|f", kwd_list, 
+                                      &dom, &cpuweight) )
+        return NULL;
+
+    if ( xc_domain_setcpuweight(xc->xc_handle, dom, cpuweight) != 0 )
+        return PyErr_SetFromErrno(xc_error);
+    
+    Py_INCREF(zero);
+    return zero;
+}
+
 static PyObject *pyxc_domain_getinfo(PyObject *self,
                                      PyObject *args,
                                      PyObject *kwds)
@@ -928,6 +945,28 @@ static PyObject *pyxc_domain_setmaxmem(PyObject *self,
     return zero;
 }
 
+static PyObject *pyxc_domain_memory_increase_reservation(PyObject *self,
+                                                        PyObject *args,
+                                                        PyObject *kwds)
+{
+    XcObject *xc = (XcObject *)self;
+
+    u32 dom;
+    unsigned long mem_kb;
+
+    static char *kwd_list[] = { "dom", "mem_kb", NULL };
+
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list, 
+                                      &dom, &mem_kb) )
+        return NULL;
+
+    if ( xc_domain_memory_increase_reservation(xc->xc_handle, dom, mem_kb) )
+        return PyErr_SetFromErrno(xc_error);
+    
+    Py_INCREF(zero);
+    return zero;
+}
+
 
 static PyMethodDef pyxc_methods[] = {
     { "domain_create", 
@@ -935,7 +974,6 @@ static PyMethodDef pyxc_methods[] = {
       METH_VARARGS | METH_KEYWORDS, "\n"
       "Create a new domain.\n"
       " dom    [int, 0]:        Domain identifier to use (allocated if zero).\n"
-      " mem_kb [int, 0]:        Memory allocation, in kilobytes.\n"
       "Returns: [int] new domain identifier; -1 on error.\n" },
 
     { "domain_dumpcore", 
@@ -976,6 +1014,14 @@ static PyMethodDef pyxc_methods[] = {
       " cpumap [int, -1]: Bitmap of usable CPUs.\n\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
+    { "domain_setcpuweight", 
+      (PyCFunction)pyxc_domain_setcpuweight, 
+      METH_VARARGS | METH_KEYWORDS, "\n"
+      "Set cpuweight scheduler parameter for domain.\n"
+      " dom [int]:            Identifier of domain to be changed.\n"
+      " cpuweight [float, 1]: VCPU being pinned.\n"
+      "Returns: [int] 0 on success; -1 on error.\n" },
+
     { "domain_getinfo", 
       (PyCFunction)pyxc_domain_getinfo, 
       METH_VARARGS | METH_KEYWORDS, "\n"
@@ -1010,14 +1056,6 @@ static PyMethodDef pyxc_methods[] = {
       " state_file [str]:    Name of state file. Must not currently exist.\n"
       " progress   [int, 1]: Bool - display a running progress indication?\n\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
-    { "plan9_build",
-      (PyCFunction)pyxc_plan9_build,
-      METH_VARARGS | METH_KEYWORDS, "\n"
-      "Build a new Plan 9 guest OS.\n"
-      " dom     [long]:     Identifier of domain to build into.\n"
-      " image   [str]:      Name of kernel image file. May be gzipped.\n"
-      " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
-      "Returns: [int] 0 on success; -1 on error.\n" },
 
     { "linux_restore", 
       (PyCFunction)pyxc_linux_restore, 
@@ -1038,6 +1076,15 @@ static PyMethodDef pyxc_methods[] = {
       " vcpus   [int, 1]:   Number of Virtual CPUS in domain.\n\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
+    { "plan9_build",
+      (PyCFunction)pyxc_plan9_build,
+      METH_VARARGS | METH_KEYWORDS, "\n"
+      "Build a new Plan 9 guest OS.\n"
+      " dom     [long]:     Identifier of domain to build into.\n"
+      " image   [str]:      Name of kernel image file. May be gzipped.\n"
+      " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
+      "Returns: [int] 0 on success; -1 on error.\n" },
+
     { "vmx_build", 
       (PyCFunction)pyxc_vmx_build, 
       METH_VARARGS | METH_KEYWORDS, "\n"
@@ -1207,6 +1254,14 @@ static PyMethodDef pyxc_methods[] = {
       " maxmem_kb [long]: .\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
+    { "domain_memory_increase_reservation", 
+      (PyCFunction)pyxc_domain_memory_increase_reservation, 
+      METH_VARARGS | METH_KEYWORDS, "\n"
+      "Increase a domain's memory reservation\n"
+      " dom [int]: Identifier of domain.\n"
+      " mem_kb [long]: .\n"
+      "Returns: [int] 0 on success; -1 on error.\n" },
+
     { NULL, NULL, 0, NULL }
 };
 
index 34178ac529d0b98e1ff261c00bf0714f689637b3..8383ee74703661f27fa5a16cefe195200a6abf52 100644 (file)
@@ -681,8 +681,7 @@ class XendDomainInfo:
             raise VmError('invalid cpu')
         cpu_weight = self.cpu_weight
         memory = memory * 1024 + self.pgtable_size(memory)
-        dom = xc.domain_create(dom= dom, mem_kb= memory,
-                               cpu= cpu, cpu_weight= cpu_weight)
+        dom = xc.domain_create(dom= dom)
         if self.bootloader:
             try:
                 if kernel: os.unlink(kernel)
@@ -693,6 +692,11 @@ class XendDomainInfo:
         if dom <= 0:
             raise VmError('Creating domain failed: name=%s memory=%d'
                           % (self.name, memory))
+        xc.domain_setcpuweight(dom, cpu_weight)
+        xc.domain_setmaxmem(dom, memory)
+        xc.domain_memory_increase_reservation(dom, memory)
+        if cpu != -1:
+            xc.domain_pincpu(dom, 0, 1<<int(cpu))
         log.debug('init_domain> Created domain=%d name=%s memory=%d', dom, self.name, memory)
         self.setdom(dom)